/**
 * 初始化路由信息
 */
const express = require('express');
const { CustomError } = require('../middleware/index.js');
const router = express.Router(); // 创建路由

const upload = require('./upload.js');
const mo_upload = require('./mo_upload');

const admin_role = require('./admin/role.js');
const admin_menu = require('./admin/menu.js');

const blog_user = require('./blog/user.js');
const blog_blogroll = require('./blog/blogroll.js');
const blog_category = require('./blog/category.js');
const blog_tags = require('./blog/tags.js');
const blog_article = require('./blog/article.js');
const blog_article_comment = require('./blog/article-comment.js');
const blog_token = require('./blog/token.js');

router.use('/upload', upload); //
router.use('/mo_upload', mo_upload);
// 后台管理
router.use('/admin/role', admin_role); // 角色
router.use('/admin/menu', admin_menu); // 菜单

// 前台blog
router.use('/blog/user', blog_user); // 用户
router.use('/blog/blogroll', blog_blogroll); // 友链
router.use('/blog/tags', blog_tags); // 文章标签
router.use('/blog/category', blog_category); // 文章分类
router.use('/blog/article', blog_article); // 文章
router.use('/blog/article/comment', blog_article_comment); // 文章评论
router.use('/blog/token', blog_token); // 刷新token

// 404 错误拦截
router.use((req, res, next) => {
  const error = new CustomError('Not Found!', 404);
  next(error);
});

module.exports = router;
